package jukebox.model.member;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import jukebox.model.common.CommentVO;
import jukebox.model.common.CommonConstants;
import jukebox.model.common.ListVO;
import jukebox.model.common.PagingBean;

import org.springframework.stereotype.Service;

@Service
public class MemberServiceImpl implements MemberService{
	@Resource(name="memberDAOImpl")
	private MemberDAO memberDAO;
	
	@Override
	public void registerMember(MemberVO mvo){
		System.out.println("registerMember 서비스");
		memberDAO.registerMember(mvo);
	}
		
	@Override
	public void updateMember(MemberVO mvo){
		System.out.println("updateMember 서비스");
		memberDAO.updateMember(mvo);
	}

	@Override
	public void dropoutMember(String id){
		memberDAO.dropoutMember(id);
	}

/**
 * List<MemberVO> 의 리턴타입을 ListVO 로 바꾸고,
 * 페이징 빈 처리를 위해 DAO 에서 두 메서드를 가져옴
 */
	@Override
	public ListVO getAllMemberList(int nowPageNo){
		ListVO vo=null;
		PagingBean bean=new PagingBean(memberDAO.contentCount(), nowPageNo);
		System.out.println(bean);
		List<MemberVO> list=memberDAO.allMemberList(bean);
		vo=new ListVO(list , bean);
		return vo;
		}
	
/**
 * 회원 로그인시 내 게시물 보기에 내가 쓴 글 페이징 처리를 위한 메서드
 */
	@Override
	public ListVO<MemberVO> myBoardList(int nowPageNo,String id) {
		ListVO vo = null;		
		System.out.println("myboardlist id : "+id);
		PagingBean pb = new PagingBean(memberDAO.myBoardListById(id),nowPageNo);
		System.out.println("myboardlist pb : "+pb.getTotalContents());
		HashMap map=new HashMap();
		map.put("id", id);
		map.put("page",nowPageNo);
		map.put("numberOfContentsPerPage", CommonConstants.CONTENT_NUMBER_PER_PAGE);
		List<MemberVO> list=memberDAO.myBoardList(map);
		System.out.println("컨트롤러 myBoardList 페이징: "+list);
		vo=new ListVO (list,pb);
		return vo;
	}
	
	/**
	 * 회원 로그인시 내 게시물 보기에 내가 쓴 Q&A 글 페이징 처리를 위한 메서드
	 */
	@Override
	public ListVO myqnaBoardListbyId(int nowPageNo, String id) {
		ListVO vo = null;	
		PagingBean pb = new PagingBean(memberDAO.myqnaBoardCountbyId(id),nowPageNo);
		System.out.println("myqnaBoardListbyId pb : "+pb.getTotalContents());
		HashMap map=new HashMap();
		map.put("id", id);
		map.put("page",nowPageNo);
		map.put("numberOfContentsPerPage", CommonConstants.CONTENT_NUMBER_PER_PAGE);
		System.out.println(map);
		List list=memberDAO.myqnaBoardListbyId(map);
		vo=new ListVO (list,pb);
		return vo;
	}

	/**
	 * 회원 로그인시 내 게시물 보기에 내가 쓴 Q&A  댓글 페이징 처리를 위한 메서드
	 */
	@Override
	public ListVO myqnaCommentListbyId(int nowPageNo, String id) {
		ListVO vo=null;
		PagingBean pb = new PagingBean(memberDAO.myqnaCommentCountbyId(id), nowPageNo);
		System.out.println("myqnaBoardListbyId pb : "+pb.getTotalContents());
		HashMap map=new HashMap();
		map.put("id", id);
		map.put("page",nowPageNo);
		map.put("numberOfContentsPerPage", CommonConstants.CONTENT_NUMBER_PER_PAGE);
		System.out.println(map);
		List list=memberDAO.myqnaCommentListbyId(map);
		vo=new ListVO (list,pb);
		return vo;
	}

	/**
	 * 회원 로그인시 내 게시물 보기에 내가 쓴 자유게시판 댓글 페이징 처리를 위한 메서드
	 */
	@Override
	public ListVO myFreeBoardCommentListbyId(int nowPageNo, String id) {
		ListVO vo=null;
		PagingBean pb = new PagingBean(memberDAO.myFreeBoardCommentCountbyId(id), nowPageNo);
		System.out.println("myqnaBoardListbyId pb : "+pb.getTotalContents());
		HashMap map=new HashMap();
		map.put("id", id);
		map.put("page",nowPageNo);
		map.put("numberOfContentsPerPage", CommonConstants.CONTENT_NUMBER_PER_PAGE);
		System.out.println(map);
		List list=memberDAO.myFreeBoardCommentListbyId(map);
		vo=new ListVO (list,pb);
		return vo;
	}

	/**
	 * 회원 로그인시 내 게시물 보기에 내가 쓴 음악 게시물 페이징 처리를 위한 메서드
	 */
	@Override
	public ListVO getMyMusicContentListById(int nowPageNo, String id) {
		ListVO vo=null;
		PagingBean pb = new PagingBean(memberDAO.getMyMusicContentCountById(id), nowPageNo);
		System.out.println("getMyMusicContentListById pb : "+pb.getTotalContents());
		HashMap map=new HashMap();
		map.put("id", id);
		map.put("page",nowPageNo);
		map.put("numberOfContentsPerPage", CommonConstants.CONTENT_NUMBER_PER_PAGE);
		System.out.println(map);
		List list=memberDAO.getMyMusicContentListById(map);
		vo=new ListVO (list,pb);
		return vo;
	}
	
	@Override
	public int checkId(String id){
		System.out.println("서비스 아이디 중복 체크 : "+id);
		return memberDAO.checkId(id);
	}

	@Override
	public int checkNickname(String nickname){
		return memberDAO.checkNickname(nickname);
		}

	@Override
	public int checkPassword(MemberVO mvo){
		return memberDAO.checkPassword(mvo);
		}

	@Override
	public MemberVO login(MemberVO mvo){
		return memberDAO.login(mvo);
		}

	@Override
	public void dropoutMemberByAdmin(String id) {
		memberDAO.dropoutMemberByAdmin(id);
	}

	@Override
	public MemberVO findId(String id) {
		return memberDAO.findId(id);
	}

	@Override
	public List<MemberVO> getRankListByLike() {
		return memberDAO.getRankListByLike();
	}
	/**
	* @method :findMyCommentListPerPage
	* @author : 조서영
	* @since : 2014-07-04
	* @return : 
	* @param : nowPage , id
	* @comment : 본인이 작성한 음악게시판 댓글보기
	 */
	@Override
	public ListVO<CommentVO> findMyCommentListPerPage(int nowPage, String id) {
		ListVO vo = null;		
		//PagingBean을 생성해준다.
				//memberDAO.myMusicCommentCountbyId() 전체 댓글 수
				//현재 페이지 nowPage
				PagingBean pb = new PagingBean(memberDAO.myMusicCommentCountbyId(id),nowPage);//int totalContents, int nowPage
				System.out.println("서비스");
				//현재페이지에 맞는 게시물정보를 가져온다.
				HashMap map=new HashMap();
				map.put("numberOfContentsPerPage", pb.getNumberOfContentsPerPage());
				map.put("id",id);
				map.put("nowPage", pb.getNowPage());
				
		List<CommentVO> list = memberDAO.findMyMusicCommentListPerPage(map); //page에 해당하는댓글들을 조회
		System.out.println(list);
		vo = new ListVO(list,pb);//List<CommentVO> list, PagingBean pagingBean
		
		return vo;
	}
}
